package com.fzg.controller;

import com.fzg.common.enums.ResponseWrapper;
import com.fzg.service.MongodbOperationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * create by fzg
 * 2022/2/11 11:17
 */

@Slf4j
@Controller
public class MongodbOperationController {

    @Autowired
    private MongodbOperationService mongodbOperationService;

    /**
     * 上传文件
     *
     * @param multipartFile 文件
     */
    @ResponseBody
    @PostMapping(value = "/upload")
    public ResponseWrapper upload(@RequestParam("file") MultipartFile multipartFile) {
        return mongodbOperationService.uploadFile(multipartFile);
    }

    /**
     * 下载文件
     *
     * @param response 响应对象
     */
    @ResponseBody
    @GetMapping("/down")
    public Map<String, Object> down(@RequestParam("enclosureId") String objectId, HttpServletResponse response){
        System.out.println(objectId);
        return mongodbOperationService.downloadFile(objectId,response);
    }


//    /**
//     * 删除文件
//     * @param param 文件id
//     */
//    @ResponseBody
//    @PostMapping("/delete")
//    public ResponseWrapper delete(@RequestBody DeleteFileParam param){
//        return mongodbOperationService.deleteFile(param);
//    }

}
